package com.mo.demo.guava;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GuavaStatusTest {
    public static void main(String[] args) {

        Cache<Integer, Integer> cache = CacheBuilder.newBuilder()
                .maximumSize(10)
                .recordStats() // 启用统计
                .build();

        for (int i = 0; i < 15; i++) {
            cache.put(i,i);
        }

        for (int i = 0; i < 20; i++) {
            cache.getIfPresent(i);
        }


        log.info("{}",cache.stats());

        // 输出：
        // 14:14:27.229 [main] INFO com.mo.demo.guava.GuavaStatusTest - CacheStats{hitCount=10, missCount=10, loadSuccessCount=0, loadExceptionCount=0, totalLoadTime=0, evictionCount=5}
    }
}
